package com.google.code.jgchart;

public class ChartData implements UrlQuery {

	private static final String PARAM = "chd=";

	private static final String CHART_DATA_TEXT_ENCODING = PARAM + "t:";

	private static final String CHART_DATA_SIMPLE_ENCODING = PARAM + "s:";

	private static final String CHART_DATA_EXTENDED_ENCODING = PARAM + "e:";

	private static final int TEXT_ENC = 1;

	private static final int SIMPLE_ENC = 2;

	private static final int EXTENDED_ENC = 4;

	private StringBuilder strData = new StringBuilder();

	private int encoding;

	protected ChartData(int enc) {
		this.encoding = enc;
	}

	public static ChartData getTextEncoding() {
		return new ChartData(TEXT_ENC);
	}

	public ChartData append(String data) {
		if (data != null && data.length() > 0) {
			strData.append(data);
		}
		return this;
	}

	public String[] getQuery() {
		StringBuilder sb = new StringBuilder();

		if (encoding == TEXT_ENC) {
			sb.append(CHART_DATA_TEXT_ENCODING).append(getDataByTextEncoding());
		} else if (encoding == SIMPLE_ENC) {
			sb.append(CHART_DATA_SIMPLE_ENCODING).append(getDataBySimpleEncoding());
		} else if (encoding == EXTENDED_ENC) {
			sb.append(CHART_DATA_EXTENDED_ENCODING).append(
					getDataByExtendedEncoding());
		}

		return new String[] { sb.toString() };
	}

	private String getDataByTextEncoding() {
		return strData.toString();
	}

	private String getDataBySimpleEncoding() {
		throw new IllegalArgumentException("TODO");
	}

	private String getDataByExtendedEncoding() {
		throw new IllegalArgumentException("TODO");
	}
}
